import {$host} from "./index";
import User from "../models/User";
import UserInfo from "../models/UserInfo";
import UpdateUserDto from "../utils/dto/user/updateUserDto";

export const getUser = async () => {
    const response = await $host.get("api/User/GetUser")
    const data = response!.data
    return response!.status === 200
        ? User.init(data.userId, data.email, data.userName, data.roles, data.userInfoId, data.userPhotoId)
        : undefined
}

export const getUserById = async (id: string) => {
    const response = await $host.get(`api/User/GetUserInfoById/${id}`)
    const data = response!.data
    return response!.status === 200
        ? new UserInfo(data.Id, data.userName, data.firstName, data.lastName, data.countryName, data.patronymic, data.imageId)
        : undefined
}

export const updateUserInfo = async (dto: UpdateUserDto) => {
    return await $host.patch('api/User/UpdateUserInfo', dto)
}


